﻿@using System.Web.Optimization
@model PhotoBlogApp.Core.Album
<style type="text/css">
    .fill-list-button {
        color: #0093c4;
        border: 1px solid transparent;
        background-color: #f4f4e1;
        cursor: pointer !important;
    }
</style>
@{
    var url = "";
    if (Request.Url != null)
    {
        url = Request.Url.GetLeftPart(UriPartial.Authority);
    }
}
<div class="block">
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">
            <hr />
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            @Html.HiddenFor(model => model.AlbumId)
            @Html.HiddenFor(model => model.UserId)

            <div class="form-group">
                @Html.LabelFor(model => model.AlbumName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.AlbumName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.AlbumName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Hide, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    <div class="checkbox">
                        @Html.EditorFor(model => model.Hide)
                        @Html.ValidationMessageFor(model => model.Hide, "", new { @class = "text-danger" })
                    </div>
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Logo, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Logo, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Logo, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Сохранить" class="btn btn-default" />
                </div>
            </div>
        </div>
    }
    <div class="col-lg-offset-2">
        <span class="btn btn-success fileinput-button">
            <i class="glyphicon glyphicon-plus"></i>
            <span>Загрузить фотографии</span>
            <input id="fileupload" type="file" name="files[]" multiple>
        </span>
        <div class="album-images-b" id="result-files">
            @if (Model.Photos.Any())
            {
                foreach (var photo in Model.Photos)
                {
                    <div class="img-b">
                        @{
                    var contentPath = Url.Content(photo.Path + "/t/" + photo.PhotoName);
                        }
                        <img src="@contentPath" />
                        <span class="img-b-delete-button">
                            @using (Html.BeginForm("DeletePhoto", "Album", new { id = photo.PhotoId, albumId = @Model.AlbumId }, FormMethod.Post))
                            {
                                <input type="submit" value="Удалить" class="btn btn-danger btn-sm" />
                            }
                        </span>
                        <span>
                            <input type="text" value="@url@contentPath" class="form-control" />
                        </span>
                    </div>
                }
            }
        </div>
    </div>

    <div>
        @Html.ActionLink("Назад", "Index")
    </div>
</div>
@section scripts
{
    @Scripts.Render("~/bundles/filupload")
    <script type="text/javascript">
        $(function () {
            $('#fileupload').fileupload({
                url: "/album/addPhotos",
                type: "POST",
                acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
                dataType: "json",
                formData: {
                    albumid: $("#AlbumId").val()
                },
                done: function (e, data) {
                    var result = data.result;
                    console.log(result);
                    if (result.IsSuccess) {
                        $("#result-files").append("<div class='img-b'><img src='" + result.Data.ThumbnailUrl + "'/></div>");
                    } else {
                        console.log(result.Errors.join());
                    }
                }
            });
        });
    </script>
}
